-
Notifications
You must be signed in to change notification settings - Fork 0
Добавляем базу данных. #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| new FilmGenreRowMapper()); | ||
|
|
||
| // пополням фильмы сведениями о жанрах | ||
| for (FilmGenre filmGenre : filmsGenres) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Предложение)Данный функционал дублируется в коде. К тому же жанры не совсем подходят под данный репозиторий. Можно вынести метод по получению жанров в GenreStorage и обогащать фильмы уже в сервисе. Но очень хорошо сделано, что обращение к бд идет не в цикле, а за константное количество запросов =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Повторяющийся код оптимизировал. Зачем нужен отдельный репозиторий для таблицы связи мне не понятно.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я не совсем про новый репозиторий. В проекте уже есть GenreDbStorage, и было бы логичнее получение жанров вынести в данный репозиторий.
| */ | ||
| @Slf4j | ||
| @Service | ||
| public class FilmService { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Для сервисов также было бы хорошо использовать интерфейсы
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Добавил интерфейсы.
| private final UserStorage users; | ||
|
|
||
| public FilmService(FilmStorage filmStorage, UserStorage users) { | ||
| public FilmService(@Qualifier("filmDbStorage") FilmStorage filmStorage, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Все InMemory реализации необходимо убрать из проекта, после этого @qualifier будет не особо нужен
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Удалил реализации InMemory.
| */ | ||
| public Film updateFilm(Film updFilm) { | ||
| Integer id = updFilm.getId(); | ||
| Film film = films.getFilmById(id).orElseThrow(() -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.orElseThrow(() лучше начинать с новой строки
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Исправлено.
| public Integer addNewLike(Integer filmId, Integer userId) { | ||
| Film film = films.getFilmById(filmId).orElseThrow(() -> | ||
| new NotFoundException("Не найден фильм id=" + filmId)); | ||
| users.getUserById(userId).orElseThrow(() -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
На 114 строчке переменная film нигде не используется в дальнейшем
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Исправлено.
|
|
||
| @Component | ||
| @Repository("inMemoryFilmStorage") | ||
| public class InMemoryFilmStorage implements FilmStorage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Все InMemory реализации необходимо удалить
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Удалил реализации InMemory.
| import java.util.*; | ||
|
|
||
| @Component | ||
| @Repository("inMemoryUserStorage") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Все InMemory реализации необходимо удалить
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Удалил реализации InMemory.
src/main/resources/schema.sql
Outdated
| -- Создаем таблицу пользователей | ||
| CREATE TABLE IF NOT EXISTS users ( | ||
| id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY, | ||
| email VARCHAR(255) NOT NULL, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
email можно сделать уникальным
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Исправил
....
email VARCHAR(255) UNIQUE NOT NULL,
....
| return films.addNewLike(filmId, userId); | ||
| } | ||
|
|
||
| public Integer removeLike(Integer filmId, Integer userId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
переменная film нигде не используется в методе, можно ее не заводить
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Исправлено.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Предложение)Упустил пару моментов в предыдущем ревью. Можно валидировать не только объекты, которые приходят в теле запроса, но и параметры, такие как count в методе findPopularFilms
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Надеюсь я правильно понял.
http://localhost:8080/films/popular?count=-1
{
"error": "400 BAD_REQUEST "Validation failure""
}
Спринт 12. часть 1. добавление базы данных.